<template>
  <div class="admin-user">
    <div class="my-admin-header">
      <div class="left">
        <h1 class="title">
          <i class="el-icon-user-solid"></i>
          用户管理
        </h1>
      </div>
    </div>
    <div class="my-admin-content">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="photo" label="头像" width="180">
          <template slot-scope="scope">
            <div class="cover-photo">
              <!-- <img :src="scope.row.photo||'../img/gan.png'" alt="头像"> -->
              <my-photo
                :photo="scope.row.photo"
                :userName="scope.row.userName"
                line-height="40px"
                font-size="40px"
              ></my-photo>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="用户名" width="180">
          <template slot-scope="scope">
            <router-link :to="{name:'personPage',query:{id:scope.row.id}}">{{scope.row.userName}}</router-link>
          </template>
        </el-table-column>
        <el-table-column prop="registerTime" label="注册时间" width="180"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row,2)" v-if="scope.row.state==1">禁用</el-button>
            <el-button size="mini" type="info" @click="handleDelete(scope.$index, scope.row,1)" v-if="scope.row.state==2">启用</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <ElPagination :total="totalRow" :current-page.sync="pageNumber" :page-size="8" background></ElPagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "admin-user",
  data: function() {
    return {
      tableData: [],
      checkState: ["未审核", "通过", "不通过"],
      pageNumber: 1,
      pageSize: 8,
      totalRow: 0,
      userName: ""
    };
  },
  methods: {
    handleDelete(index, obj,state) {
      
      /* this.$confirm("禁用用户?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => { */
          this.axios
            .post("admin/userState", {
              id:obj.id,
              state:state
            })
            .then(res => {
              if (res.data.success) {
                this.$message({
                  type: "success",
                  message: "操作成功!"
                });
                this.getUserList();
              }
            });
        /* })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        }); */
    },
    getUserList() {
      this.axios
        .post("admin/userList", {
          userName: this.userName,
          pageNumber:this.pageNumber,
          pageSize:this.pageSize
        })
        .then(res => {
          this.totalRow = res.data.page.totalRow;
          this.tableData = res.data.page.list;
        });
    }
  },
  watch: {
    pageNumber: function() {
      this.getUserList();
    }
  },
  mounted: function() {
    this.getUserList();
  }
};
</script>

<style lang="scss" scoped>
.cover-photo {
  height: 45px;
  width: 80px;
}
img {
  height: 100%;
  width: 100%;
}
.pagination {
  margin-top: 20px;
}
</style>